package com.mep.auth.controller;

import com.mep.auth.feign.IFeignSysMenuApi;
import com.mep.auth.model.SysMenu;
import com.mep.auth.service.SysMenuService;
import com.mep.common.http.HttpResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 菜单控制器
 * @author lyl
 * @date Jan 13, 2019
 */

@Api(value="003-menu的controller",tags="003-menu的controller")
@RestController
@RequestMapping("menu")
public class SysMenuController implements IFeignSysMenuApi {

	@Autowired
	private SysMenuService sysMenuService;

	@Override
	@ApiOperation(value="01.保存菜单信息",notes="问题点:保存菜单信息")
	@ApiOperationSupport(order = 1, author = "lyl")
	//@PostMapping(value="/save")
	public HttpResult save(@RequestBody SysMenu record) {
		return HttpResult.ok(sysMenuService.save(record));
	}

	@Override
	@ApiOperation(value="02.删除菜单信息",notes="问题点:删除菜单信息")
	@ApiOperationSupport(order = 2, author = "lyl")
	//@PostMapping(value="/delete")
	public HttpResult delete(@RequestBody List<SysMenu> records) {
		return HttpResult.ok(sysMenuService.delete(records));
	}

	@Override
	@ApiOperation(value="03.根据用户名查询菜单树信息",notes="问题点:根据用户名查询菜单树信息")
	@ApiOperationSupport(order = 3, author = "lyl")
	//@GetMapping(value="/findNavTree")
	public HttpResult findNavTree(@RequestParam String userName) {
		return HttpResult.ok(sysMenuService.findTree(userName, 1));
	}

	@Override
	@ApiOperation(value="04.查询整个菜单树信息",notes="问题点:查询整个菜单树信息")
	@ApiOperationSupport(order = 4, author = "lyl")
	//@GetMapping(value="/findMenuTree")
	public HttpResult findMenuTree() {
		return HttpResult.ok(sysMenuService.findTree(null, 0));
	}
}
